package com.brainhealth.quartz.task;

import com.brainhealth.common.constant.CacheConstants;
import com.brainhealth.common.core.redis.RedisCache;
import com.brainhealth.customer.service.ICustomerExerciseService;
import com.brainhealth.customer.service.ICustomerService;
import com.brainhealth.customer.service.IErnieBotService;
import com.brainhealth.quartz.service.IBuriedPointService;
import com.brainhealth.quartz.service.IChatJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Iterator;

@Component("brainTask")
public class BrainTask {
    @Autowired
    RedisCache redisCache;
    @Resource
    ICustomerExerciseService customerExerciseService;
    @Autowired
    IChatJobService chatJobService;
    @Autowired
    IBuriedPointService buriedPointService;
    @Autowired
    ICustomerService customerService;
    @Autowired
    IErnieBotService ernieBotService;
    /**
     * 定时任务清理会员签到信息
     */
    public void clearCustomerSign() {
        Collection<String> collection = redisCache.keys(CacheConstants.CUSTOMER_SIGN + "*");
        if (collection.size() > 0) {
            Iterator iterator = collection.iterator();
            while (iterator.hasNext()) {
                iterator.remove();
            }
        }
    }

    /**
     * 修改会员超过3天过期训练状态
     */
    public void customerExerciseExpired()
    {
        customerExerciseService.customerExerciseExpired();
    }

    /**
     * 清理聊天记录
     */
    public void clearChatRecord() {
      chatJobService.clearChatRecord();
    }

    /**
     * 推送登录
     */
    public void pushLogin() {
        chatJobService.pushLogin();
    }

    /**
     * 开启下一个订单任务
     */
    public void openNextTask() {
        chatJobService.openNextTask();
    }

    /**
     * 新增埋点统计结果
     */
    public void buriedPointService() {
        buriedPointService.insertBuriedPointResult();
    }

    /**
     * 新增用户事件埋点统计结果
     */
    public void insertUserEventBuriedPointResult(){
        buriedPointService.insertUserEventBuriedPointResult();
    }

    /**
     * 重置体验会员状态
     */
    public void resetExperienceCustomer()
    {
        customerService.resetExperienceCustomer();
    }

    /**
     * 刷新文心一言token缓存
     */
    public void refreshErnieBotToken()
    {
        ernieBotService.refreshToken();
    }

}
